package com.hzcc.hzccblog.module.service.impl;

import com.hzcc.hzccblog.common.enums.AuthEnums;
import com.hzcc.hzccblog.module.service.AuthService;
import com.hzcc.hzccblog.utils.JWTUtil;
import com.hzcc.hzccblog.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

import static com.hzcc.hzccblog.common.Constant.LOGIN_TOKEN;

/**
 * @Author 早睡蛋
 * @Date 2022/7/17 20:27:17
 * @Desc:
 */
@Service
public class AuthServiceImpl implements AuthService {

    @Resource
    private RedisUtil redisUtil;

    @Override
    public boolean isLogin(String token) {
            System.out.println(token);
            if (token==null || token==""){
                return false;
            }
            String userToken = token.substring(0,token.length()-1);
            Map<String, Object> stringObjectMap = JWTUtil.verify1(userToken);
            String email = (String) stringObjectMap.get("email");
            System.out.println(email);
            boolean b = redisUtil.existsString(LOGIN_TOKEN + email);
            if (!b){
                return false;
            }
            return true;

    }
}
